<?php
/**
 * Description of Emms_Report_WriteOffs
 *
 * @author andres
 */
class Emms_Report_WriteOffs extends HTech_Report
{
    protected function _setName() 
    {
        $this->_name = $this->translate('Loan write-offs');
    }

    protected function _setForm() 
    {
        $this->_form = new HTech_Report_Form_DateRange();
    }
    
    protected function _setIndex() {}

    protected function _setSql() 
    {
        $this->_sql = '
            select 
                lwo.*,
                cy.Cycle LoanCycle,
                cybln.Cycle LoanCycleByLine,
                cybpg.Cycle LoanCycleByProgram,
                cybpd.Cycle LoanCycleByProduct
            from 
                view_loan_write_offs lwo
            left join
                loan_cycles cy on cy.LoanId = lwo.LoanId
            left join
                loan_cycles_by_line cybln on cybln.LoanId = lwo.LoanId
            left join
                loan_cycles_by_program cybpg on cybpg.LoanId = lwo.LoanId
            left join
                loan_cycles_by_product cybpd on cybpd.LoanId = lwo.LoanId
            where 
                lwo.WriteOffDate >= :dateFrom and 
                lwo.WriteOffDate <= :dateTo';
    }
    
    protected function _setHeaders()
    {
        $this->_headers = new stdClass();
        $this->_headers->WriteOffId = $this->translate('Write-off Id');
        $this->_headers->LoanId = $this->translate('Loan Id');
        $this->_headers->LoanCycle = $this->translate('Loan cycle');
        $this->_headers->LoanCycleByLine = $this->translate('Loan cycle by line');
        $this->_headers->LoanCycleByProgram = $this->translate('Loan cycle by program');
        $this->_headers->LoanCycleByProduct = $this->translate('Loan cycle by product');
        $this->_headers->ClientId = $this->translate('Client Id');
        $this->_headers->ClientCode = $this->translate('Client code');
        $this->_headers->ClientFullName = $this->translate('Client name');
        $this->_headers->ClientNickName = $this->translate('Nickname');
        $this->_headers->ClientGender = $this->translate('Gender');
        $this->_headers->ClientHomePhone = $this->translate('Home phone');
        $this->_headers->ClientMobilePhone = $this->translate('Mobile phone');
        $this->_headers->BusinessType = $this->translate('Business');
        $this->_headers->BusinessActivity = $this->translate('Activity');
        $this->_headers->LoanProductName = $this->translate('Loan product');
        $this->_headers->ProductLine = $this->translate('Line');
        $this->_headers->Program = $this->translate('Program');
        $this->_headers->Fund = $this->translate('Fund');
        $this->_headers->LocationShortName = $this->translate('Branch');
        $this->_headers->Community = $this->translate('Community');
        $this->_headers->OfficerUsername = $this->translate('Officer');
        $this->_headers->WriteOffDate = $this->translate('Write-off date');
        $this->_headers->Amount = $this->translate('Writen-off total');
        $this->_headers->Principal = $this->translate('Principal');
        $this->_headers->LoanInsurance = $this->translate('Loan insurance');
        $this->_headers->HealthInsurance = $this->translate('Health insurance');
        $this->_headers->AdministrativeFee = $this->translate('Admin. fee');
        $this->_headers->Interest = $this->translate('Interest');
        $this->_headers->Penalties = $this->translate('Penalties');
        $this->_headers->DeliveryDate = $this->translate('Disbursement date');
        $this->_headers->PrincipalDisbursed = $this->translate('Principal disbursed');
        $this->_headers->PrincipalCharges = $this->translate('Principal charges');
        $this->_headers->PrincipalPayments = $this->translate('Principal payments');
        $this->_headers->PrincipalBalance = $this->translate('Principal balance');
        $this->_headers->LoanInsuranceCharges = $this->translate('Loan insurance charges');
        $this->_headers->LoanInsurancePayments = $this->translate('Loan insurance payments');
        $this->_headers->LoanInsuranceBalance = $this->translate('Loan insurance balance');
        $this->_headers->HealthInsuranceCharges = $this->translate('Health insurance charges');
        $this->_headers->HealthInsurancePayments = $this->translate('Health insurance payments');
        $this->_headers->HealthInsuranceBalance = $this->translate('Health insurance balance');
        $this->_headers->AdministrativeFeeCharges = $this->translate('Admin. fee charges');
        $this->_headers->AdministrativeFeePayments = $this->translate('Admin. fee payments');
        $this->_headers->AdministrativeFeeBalance = $this->translate('Admin. fee balance');
        $this->_headers->InterestBalance = $this->translate('Interest balance');
        $this->_headers->PenaltiesBalance = $this->translate('Penalties balance');
        $this->_headers->Status = $this->translate('Current Status');
    }
    
    public function setParams($params) 
    {
        $this->_params = array(
            ':dateFrom' => $params['DateFrom'],
            ':dateTo' => $params['DateTo']);
    }

}
